<template>
  <div class="app-container">
    <el-form :inline="true" label-width="">
      <el-form-item label="手机/真实姓名">
        <el-input
          v-model="queryParams.realname"
          placeholder="手机/真实姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="类型">
        <el-select v-model="queryParams.status" placeholder="类型" clearable size="small">
          <el-option
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="申请时间">
        <el-date-picker
          v-model="daterange"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <!--<el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['system:post:add']">新增</el-button>-->
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="postList">
      <el-table-column label="真实姓名" align="center" prop="realname"/>
      <el-table-column label="手机号码" align="center" prop="channelUser.mobile"/>
      <el-table-column label="证件号码" align="center" prop="idcard">
        <template slot-scope="scope">
          <el-popover placement="top-start" title="账号" width="250" trigger="hover">
            <div>{{scope.row.idcard}}</div>
            <span slot="reference" v-if="scope.row.idcard">{{ scope.row.idcard.substr(0,10)+'...' }}</span>
            <span slot="reference" v-else class="text-info">无</span>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="账号类型" align="center" prop="accounttype"/>
      <el-table-column label="账号" align="center" prop="accountno">
        <template slot-scope="scope">
          <el-popover placement="top-start" title="账号" width="250" trigger="hover">
            <div>{{scope.row.accountno}}</div>
            <span slot="reference" v-if="scope.row.accountno">{{ scope.row.accountno.substr(0,10)+'...' }}</span>
            <span slot="reference" v-else class="text-info">无</span>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="支行信息" align="center" prop="accountbranch"></el-table-column>
      <el-table-column label="申请金额" align="center" prop="amount">
        <template slot-scope="scope">
          <span>{{(scope.row.amount+scope.row.fee)|currencyFilter}}</span>
        </template>
      </el-table-column>
      <el-table-column label="手续费" align="center" prop="fee">
        <template slot-scope="scope">
          <span>{{scope.row.fee|currencyFilter}}</span>
        </template>
      </el-table-column>
      <el-table-column label="实提金额" align="center">
        <template slot-scope="scope">
          <span>{{scope.row.amount|currencyFilter}}</span>
        </template>
      </el-table-column>
      <el-table-column label="提现状态" align="center" prop="status">
        <template slot-scope="scope">
          <span class="text-danger" v-if="scope.row.status===0">{{statusFormat(scope.row,scope.row.status)}}</span>
          <span v-else-if="scope.row.status===1">{{statusFormat(scope.row,scope.row.status)}}</span>
          <span v-else-if="scope.row.status===2">{{statusFormat(scope.row,scope.row.status)}}</span>
          <span class="text-success"
                v-else-if="scope.row.status===3">{{statusFormat(scope.row,scope.row.status)}}</span>
        </template>
      </el-table-column>
      <el-table-column label="申请时间" align="center" prop="createtime"
                       :show-tooltip-when-overflow="true"></el-table-column>
      <el-table-column label="操作" align="center" prop="datetime" width="200">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="primary"
            @click="handlePlatformAudit(scope.row)"
            v-if="scope.row.status===1"
            v-hasPermi="['main:banner:edit']"
          >平台审核
          </el-button>
          <el-button
            size="mini"
            type="success"
            @click="handlePaymentCompleted(scope.row)"
            v-if="scope.row.status===2"
            v-hasPermi="['main:banner:edit']"
          >出款完成
          </el-button>
          <el-button
            size="mini"
            type="danger"
            @click="handleRefuse(scope.row)"
            v-hasPermi="['main:banner:remove']"
            v-if="scope.row.status!==3&&scope.row.status!==0"
          >拒绝
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog :title="title" :visible.sync="open" width="600px" :close-on-click-modal="false">
      <el-form ref="form" label-width="80px">
        <el-form-item label="拒绝原因">
          <el-input type="textarea"
                    v-model="form.remark"
                    maxlength="500"
                    show-word-limit
                    :rows="5" placeholder="请输入拒绝理由"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" :disabled="addLoading"

                   @click.native.prevent="submitForm">
          <span v-if="!addLoading">提 交</span>
          <span v-else>提 交 中...</span>
        </el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />


  </div>
</template>

<script>
  import {takeList, takeUpdate, platformAudit, paymentCompleted, refuse} from "@/api/channel/take";

  export default {
    data() {
      return {
        form: {
          id: undefined,
          remark: ''
        },
        addLoading: false,
        daterange: '',
        open: false,
        // 遮罩层
        loading: true,
        // 总条数
        total: 0,
        // 岗位表格数据
        postList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        //open: false,
        // 状态数据字典
        statusOptions: [
          {dictLabel: '已拒绝', dictValue: 0},
          {dictLabel: '平台审核中', dictValue: 1},
          {dictLabel: '银行处理中', dictValue: 2},
          {dictLabel: '到账成功', dictValue: 3}],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          realname: undefined,
          status: undefined
        },
      };
    },
    created() {
      this.getList();
    },
    methods: {
      getList() {
        this.loading = true;
        takeList(this.queryDateRange(this.queryParams, this.daterange)).then(response => {
          console.log(response.rows);
          this.postList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 岗位状态字典翻译
      statusFormat(row, column) {
        return this.selectDictLabel(this.statusOptions, column);
      },
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      handleRefuse(row) {
        this.cancel();
        this.form.id = row.id;
        this.title = '审核';
        this.open = true;
      },
      handlePlatformAudit(row) {
        let _this = this;
        this.$confirm(`确定要更改当前的状态为银行处理中？`, "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "info"
        }).then(function () {
          platformAudit({id: row.id, status: 2}).then(res => {
            console.log(res);
            _this.msgSuccess("操作成功");
            _this.getList();
          });
        }).catch(function (e) {
          console.log(e);
        });
      },
      handlePaymentCompleted(row) {
        let _this = this;
        this.$confirm(`确定要更改当前的状态为到账成功？`, "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "info"
        }).then(function () {
          paymentCompleted({id: row.id, status: 3}).then(res => {
            console.log(res);
            _this.msgSuccess("操作成功");
            _this.getList();
          });
        }).catch(function (e) {
          console.log(e);
        });
      },
      submitForm() {
        this.addLoading = true;
        refuse({id: this.form.id, status: 0, remark: this.form.remark}).then(res => {
          this.msgSuccess("操作成功");
          this.getList();
          this.open = false;
        });
      },
      cancel() {

        this.form = {
          id: undefined,
          remark: ''
        };
        this.addLoading = false;
      }

    }
  };
</script>
